package com.gudaomai.ekproject.common;

import java.sql.Timestamp;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import com.baomidou.mybatisplus.mapper.MetaObjectHandler;
@Component
public class MyMetaObjectHandler extends MetaObjectHandler{

	/**
     * 测试 user 表 name 字段为空自动填充
     */
    public void insertFill(MetaObject metaObject) {
        Object createTime = metaObject.getValue("createTime");
        Object createUser = metaObject.getValue("createUser");
        Timestamp ts =new Timestamp(System.currentTimeMillis());
        //String userCd = new CommonUtil().getCurrentUser().getId();
        String userCd="12345678901234567890123456789012";
        if (null == createTime) {
            metaObject.setValue("createTime", ts);
            metaObject.setValue("updateTime", ts);
        }
        if (null == createUser) {
            metaObject.setValue("createUser", userCd);
            metaObject.setValue("updateUser", userCd);
        }
    }
    
    @Override
    public void updateFill(MetaObject metaObject) {
        Timestamp ts =new Timestamp(System.currentTimeMillis());
        //String userid = new CommonUtil().getCurrentUser().getId();
        String userid="12345678901234567890123456789012";
    	Object createTime = metaObject.getValue("createTime");
        Object createUser = metaObject.getValue("createUser");
        if(createTime==null){
        	metaObject.setValue("createTime", ts);
        }
        if(createUser==null){
        	metaObject.setValue("createUser", userid);
        }

        metaObject.setValue("updateTime", ts);
        metaObject.setValue("updateUser", userid);
    }
}
